import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/**
    进度条
 */
class ProgressWidget extends StatefulWidget {
  ProgressWidget({
    Key? key,
    @required this.text,
  }) : super(key: key);
  final String? text;

  @override
  State<StatefulWidget> createState() {
    return _ProgressState(text ?? "");
  }
}

class _ProgressState extends State<ProgressWidget>
    with SingleTickerProviderStateMixin {
  String? title;

  _ProgressState(String? text) {
    title = text;
  }

  //动画
  AnimationController? _animationController;

  @override
  void initState() {
    //动画执行时间3秒
    _animationController =
        new AnimationController(vsync: this, duration: Duration(seconds: 3));
    //
    _animationController?.forward();
    _animationController?.addListener(() => setState(() => {
          // 用于实时更新_animation.value
        }));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[300], //背景色
        appBar: AppBar(
          title: Text(title ?? ""),
        ),
        body: Container(
          padding: EdgeInsets.only(left: 28.0, top: 80.0, right: 28.0),
          child: Column(
            children: <Widget>[
              LinearProgressIndicator(
                minHeight: 10,
                backgroundColor: Colors.grey[200],
                valueColor: ColorTween(begin: Colors.grey, end: Colors.blue)
                    .animate(_animationController!), // 从灰色变成蓝色
                value: _animationController?.value,
              ),
              SizedBox(
                height: 30,
              ),
              CircularProgressIndicator(
                backgroundColor: Colors.grey[200],
                valueColor: ColorTween(begin: Colors.grey, end: Colors.blue)
                    .animate(_animationController!), // 从灰色变成蓝色
                value: _animationController?.value,
              ),
            ],
          ),
        ));
  }

  @override
  void dispose() {
    super.dispose();
    _animationController?.dispose();
  }
}
